* PANEL C OF TABLES 1 AND 2: DiD ESTIMATIONS COMPARING OW TO ALL OTHER CANTONS * 

/*
Tables of the paper: 
		- Table 1, Panel C (analysis at treatment group level)
		- Table 2, Panel C (analysis at treatment group level)
*/


// NOTE: data needed for this do-file cannot be shared due to privacy reasons

/* following packages need to be installed:
ssc install winsor2
ssc install reghdfe
ssc install boottest
ssc install estout
*/



version 16.1

clear all
cap log close 
cap clear matrix
set more off
cap set scheme mygraphs



*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

*   LOAD & PREPARE THE DATA for analysis at canton level, without controls
*	- columns 1-5 

run "$mypathRR/Resources/prep_treatgroup_level_data.do"

global yrs20012016 "year > 2000 & year < 2017"
global yrs19952016 "year > 1994 & year < 2017"
global yrsall "year =!."

* only years for which data on OW is available
drop if year < 1995
drop if (year == 1996 | year == 1998 | year == 1999 | year == 2000) 

// only look at those outcomes where parallel trends look ok according to ES-estimates
global outcomes "share300K share200K reink reink_w reink_ctrl reink_tr reink_tr_w"


foreach outcome in $outcomes {
// m0: baseline (time FE, weights)
		reghdfe `outcome' Interaction treated period [aweight = weight_`outcome'] if $yrs19952016 , absorb(year) vce(robust)
eststo m0_`outcome'

// add stats to be passed on to estout
	estimates restore m0_`outcome'
	summ `outcome' if e(sample)  & OW == 1& year < 2006 [aweight = weight_`outcome']
	local average = r(mean)
	estadd scalar yavg = `average'
	estimates store m0_`outcome'
	
	
// m2: baseline (no time FE, weights)
		reghdfe `outcome' Interaction treated period [aweight = weight_`outcome'] if $yrs19952016 , noabsorb vce(robust)
eststo m2_`outcome'

// add stats to be passed on to estout
	estimates restore m2_`outcome'
	summ `outcome' if e(sample)  & OW == 1& year < 2006 [aweight = weight_`outcome']
	local average = r(mean)
	estadd scalar yavg = `average'
	estimates store m2_`outcome'


// m1: baseline (time FE, weights, no clustering, correcting for pre-trend)
		reghdfe resid`outcome' Interaction treated period [aweight = weight_`outcome'] if $yrs19952016 , absorb(year) vce(robust)
eststo m1_`outcome'

// add stats to be passed on to estout
	estimates restore m1_`outcome'
	summ `outcome' if e(sample)  & OW == 1& year < 2006 [aweight = weight_`outcome']
	local average = r(mean)
	estadd scalar yavg = `average'
	estimates store m1_`outcome'
}	






*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

*   LOAD & PREPARE THE DATA for analysis at canton level, with controls
*	- column 6

run "$mypathRR/Resources/prep_treatgroup_level_data_controls.do"

global yrs20012016 "year > 2000 & year < 2017"
global yrs19952016 "year > 1994 & year < 2017"
global yrsall "year =!."

* only years for which data on OW is available
drop if year < 1995
drop if (year == 1996 | year == 1998 | year == 1999 | year == 2000) 

// only look at those outcomes where parallel trends look ok according to ES-estimates
global outcomes "reink"

global controls " nowork retiree self married singlep marriedch "

foreach outcome in $outcomes {
// m4: CLUSTER (mun & time FE, weights, clustered at canton level)
reghdfe resid`outcome' Interaction treated period $controls [aweight = weight_`outcome'] if $yrs19952016, absorb(year) vce(robust)
eststo m1c_`outcome'


// add stats to be passed on to estout
	estimates restore m1c_`outcome'
	summ `outcome' if e(sample)  & OW == 1 & year < 2006 [aweight = weight_`outcome']
	local average = r(mean)
	estadd scalar yavg = `average'
	estimates store m1c_`outcome'	
	
}	



*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

// OUTPUT TABLES TO LATEX
cd "$mypathRR/Results/"	
 
* TABLE 1, panel B 
estout m0_share300K m1_share300K  using "Tab1_PanelC)-DID-share300K.tex" 		///
, replace style(tex) cells( "b(star fmt(3))" "se(fmt(2) par)") 					///
keep(Interaction) varlabels(Interaction "DiD") 									///
stats(N r2 yavg, 																///
fmt( %9.0g  %9.2f %9.3f ) layout( @ @ @ )										///
labels("\addlinespace[1.5ex] N" "R$^2$" "\addlinespace[1.5ex] \midrule $\overline{Y}_{t<2006}$ " )) ///
mlabels(none)  collabels(none)  	
	

* TABLE 2, panel B with winsorized values 
estout m0_reink_w m1_reink_w  m1_reink_ctrl m1_reink_tr_w m1c_reink using "Tab2_PanelC)-DID-reink_winsor.tex" 			///
, replace style(tex) cells( "b(star fmt(2))" "se(fmt(2) par)") 					///
keep(Interaction) varlabels(Interaction "DiD") 									///
stats(N r2  yavg, 																///
fmt( %9.0g  %9.2f  %9.3f ) layout( @ @  @ )										///
labels( "\addlinespace[1.5ex] N" "R$^2$" "\addlinespace[1.5ex] \midrule $\overline{Y}_{t<2006}$ " )) ///
mlabels(none)  collabels(none)  					


						* * * * *  E N D  * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
